CommandPost: transparently allow multi-word commands #224
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A bunch of the lingering EasyListening reactors are doing that because they want commands like "verb subthing" and "verb othersubthing". The CommandPost translations of that would come in two forms, until now, neither very appealing.
For one, you might make a "verb" command which then subparses. This loses a bunch of nice properties of commandpost, like the parser system.
For the other, you could make a responder, which just has the same problem.
I've long considered a means to say "add this reactor with a prefix word", so you could make "subthing" and "othersubthing" commands, and give the reactor a "verb" prefix. That would also allow the reactor to be configured twice with distinct prefixes. I think this is still a good idea.
The change made in this commit, though, is smaller in scope. It allows command names and aliases to have spaces in them. If they do, they're matched differently. We can't just split off the first word and look things up in a hash. Instead, we do a regex match. To avoid doing 100 regex matches per message if there are 100 commands, we only do the regex match for multi-word commands, and only if any multi-word commands have been registered. This implementation detail should be invisible to the user, and so can be changed later.
Prefix conflicts (the command "eat" and "eat pie" both being registered, for example) are not handled. They will handled implicitly by the fact that the PotentialReactions of commands are always flagged exclusive.